﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CommonHelper.Model.Qy;
using CommonHelper.Server.Qy;

namespace WeiXinGeneralApi.Controllers.Qy
{
    public class QyWeiXinController : Controller
    {
        private static AccessTokenHelper _accessTokenHelper = AccessTokenHelper.GetInstance();
        //
        // GET: /QyWeiXin/

        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public ActionResult GetAccessToken()
        {
            return View();
        }

        [HttpPost]
        public ActionResult GetAccessToken(string corpId, string corpSecret)
        {
            var result = string.Empty;
            try
            {
                result = _accessTokenHelper.GetAccessToken(corpId, corpSecret, DateTime.Now);

            }
            catch (InvalidOperationException ex)
            {
                result = ex.Message;
            }
            catch (Exception e)
            {
                result = e.Message;
            }
            return Json(result);
        }

        /// <summary>
        /// 部门管理
        /// </summary>
        /// <returns></returns>
        public ActionResult Department()
        {
            return View();
        }

        /// <summary>
        /// 用户管理
        /// </summary>
        /// <returns></returns>
        public ActionResult User()
        {
            return View();
        }
    }
}
